package com.ruoyi.edh.mapper;

import com.ruoyi.edh.domain.EdhCouponLog;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.HashMap;
import java.util.List;


/**
 * 易订货-优惠券记录Mapper接口
 *
 * @author xxx
 * @date 2020-09-02
 */
public interface EdhCouponLogMapper {
    /**
     * 查询易订货-优惠券记录
     *
     * @param id 易订货-优惠券记录ID
     * @return 易订货-优惠券记录
     */
    public EdhCouponLog selectEdhCouponLogById(Long id);

    /**
     * 根据我的id和优惠卷id查询出优惠卷
     *
     * @param id 易订货-优惠券记录ID
     * @return 易订货-优惠券记录
     */
    public EdhCouponLog selectMyEdhCouponLogById(@Param("id") Long id, @Param("userId") Long userId);

    EdhCouponLog selectOneEdhCouponLogById(@Param("couponId") Long couponId, @Param("userId") Long userId);

    /**
     * 查询易订货-优惠券记录列表
     *
     * @param edhCouponLog 易订货-优惠券记录
     * @return 易订货-优惠券记录集合
     */
    public List<EdhCouponLog> selectEdhCouponLogList(EdhCouponLog edhCouponLog);

    /**
     * 新增易订货-优惠券记录
     *
     * @param edhCouponLog 易订货-优惠券记录
     * @return 结果
     */
    public int insertEdhCouponLog(EdhCouponLog edhCouponLog);

    /**
     * 修改易订货-优惠券记录
     *
     * @param edhCouponLog 易订货-优惠券记录
     * @return 结果
     */
    public int updateEdhCouponLog(EdhCouponLog edhCouponLog);

    /**
     * 删除易订货-优惠券记录
     *
     * @param id 易订货-优惠券记录ID
     * @return 结果
     */
    public int deleteEdhCouponLogById(Long id);

    /**
     * 批量删除易订货-优惠券记录
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    public int deleteEdhCouponLogByIds(Long[] ids);

    /**
     * @param
     * @description: 查询未使用的优惠卷
     * @return: List<EdhCouponLog>
     * @author: 梁东宸
     * @time: 2020/9/18 1:45 下午
     */
    public List<EdhCouponLog> queryNotExpiredUserCoupon();

    /**
     * @param id
     * @description: 根据id修改已失效的优惠卷
     * @return: Integer
     * @author: 梁东宸
     * @time: 2020/9/18 1:51 下午
     */
    public Integer updateExpiredUserCoupon(String id);

    @Select(value = "select coupon.id , coupon.name , coupon.`condition` , coupon.money" +
            " ,date_format(log.use_start_time,'%Y-%m-%d') userStartTime" +
            " ,date_format(log.use_end_time,'%Y-%m-%d') userEndTime" +
            " from edh_coupon_log log " +
            " left join edh_coupon coupon on log.coupon_id = coupon.id " +
            " where log.user_id = #{userId} and log.status =0 " +
            " and now() between log.use_start_time and log.use_end_time ")
    List<HashMap<String, Object>> normalList(@Param("userId") Long userId);

    @Select(value = "select  coupon.id ,coupon.name , coupon.`condition` , coupon.money" +
            " ,date_format(log.use_start_time,'%Y-%m-%d') userStartTime" +
            " ,date_format(log.use_end_time,'%Y-%m-%d') userEndTime" +
            " from edh_coupon_log log " +
            " left join edh_coupon coupon on log.coupon_id = coupon.id " +
            " where log.user_id = #{userId} and log.status =2 " +
            " and now() not between log.use_start_time and log.use_end_time ")
    List<HashMap<String, Object>> expireList(@Param("userId") Long userId);

}
